﻿<nav class="main">
    <ul class="menu">
        @foreach (var navigator in GetRootNavigator().Children)
        {
            <li><a @if (navigator.Key.IsMatched(ViewBag.MainMenu as string))
                   { @:class="active" 
                    } href="@navigator.NavigatorUrl"><span>
                        <h2>@navigator.DisplayName</h2>@navigator.EnglishName.ToUpper()</span></a></li>
            <li class="sep"></li>
        }
    </ul>
    @foreach (var main in GetRootNavigator().Children)
    {
        if (main.Key.IsMatched(ViewBag.MainMenu as string) && main.Children.Count > 0)
        {
        <div class="menupanel">
            <div class="submenu">
                <ul class="fleft">
                    @for (var i = 0; i < main.Children.Count; i++)
                    {
                        @DisplaySubMenu(main.Children[i], i > 0)
                    }
                </ul>
            </div>
            <div class="clear"></div>
        </div>
        }
    }
</nav>

@helper DisplaySubMenu(Navigator navigator, bool addSeporator = true)
    {
        if (addSeporator)
        {<li class="sep"></li>}
        if(string.IsNullOrEmpty(navigator.DisplayName))
        {<li>@navigator.Title</li>}
        if (navigator.Key.IsMatched((string)ViewBag.SubMenu))
        {<li><a href="@navigator.NavigatorUrl" class="active">@navigator.DisplayName</a></li>}
        else
        {<li><a href="@navigator.NavigatorUrl">@navigator.DisplayName</a></li>}
}
@helper DisplaySubMenu(string key, string url, string display, bool addSeporator = true)
    {
        if (addSeporator)
        {<li class="sep"></li>}
        if (key.IsMatched((string)ViewBag.SubMenu))
        {<li><a href="@url" class="active">@display</a></li>}
        else
        {<li><a href="@url">@display</a></li>}
}